package com.tz.web.shoporder;

import com.tz.auth.AuthPassport;
import com.tz.bean.TzParams;
import com.tz.service.dictinfo.IDictInfoService;
import com.tz.service.receivetest.IReceiveTestService;
import com.tz.service.shoporder.IShoporderService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 维修订单Controller
 */
@Controller
@RequestMapping("/admin/order")
public class RepairController {

    @Resource
    private IShoporderService shoporderService;

    @Resource
    private IReceiveTestService receiveTestService;

    @Resource
    private IDictInfoService ddictInfoService;

    /*列表查询*/
    @AuthPassport
    @RequestMapping("/repair/list")
    public String list(TzParams params ,Model model){
        return "order/repair/list";
    }

    /*模板页面*/
    @RequestMapping("/repair/template")
    public String template(TzParams params ,Model model){
        List<Map<String ,Object>> repairshopStatus  =  shoporderService.getAllRepairStatus();
        model.addAttribute("repairshopStatus" , repairshopStatus);
        params.setType("002");
        model.addAttribute("datas", shoporderService.findShoporders(params));
        model.addAttribute("itemCount", shoporderService.count(params));
        return "order/repair/template";
    }


    //维修订单详情页面
    @AuthPassport
    @RequestMapping("/repair/detail/{orderno}")
    public String detail(@PathVariable("orderno")String orderno ,Model model){
        //根据订单号查询 维修订单的相关信息
        Map<String , Object>   order =  shoporderService.findShopOrderByOrderno(orderno);
        //根据订单号查询维修订单的商品信息
        Map<String , Object> gooddetail = shoporderService.selectServiceOrderDetailByOrderno2(orderno);
        //查询服务信息详情
        Map<String , Object> servicedetail = shoporderService.selectServiceInfo2(orderno);
        //根据订单号查询收货证明
        HashMap<String , Object> receiveTest =  receiveTestService.getByOrderno(orderno);
        //查询服务商品的所有图片
        List<HashMap<String, Object>> pictures = shoporderService.getAllServicepictures(orderno);
        //查询服务商品的检测报告图片
        List<HashMap<String, Object>> rpictures = shoporderService.getcheckportServicepictures(orderno);
        model.addAttribute("rpictures" , rpictures);
        model.addAttribute("order" , order);
        model.addAttribute("gooddetail" , gooddetail);
        model.addAttribute("servicedetail" , servicedetail);
        model.addAttribute("pictures" , pictures);
        model.addAttribute("receiveTest" , receiveTest);
        return "order/repair/detail";
    }

    @AuthPassport
    @ResponseBody
    @RequestMapping(value="/repair/delete",method= RequestMethod.POST)
    public String delete(TzParams params){
        shoporderService.delete(params);
        return "success";
    }

}
